<template>
  <el-upload class="upload-demo" action="#" ref="upload" :on-remove="removeFun" :auto-upload="false" :limit="1"
    :on-exceed="handleExceed" :on-change="onFun" </el-upload>

</template>
<script setup>
// import { useI18n } from "vue-i18n"
import { ref } from "vue";
import { readExcel } from '@/components/ImportExcel.js';
import { ElMessage } from "element-plus";
function getMaxLenInArr(arr) {

}
const upload = ref();
let fd = null;
let fileData = ref(null);
function onFun(file) {
  if (file.name.indexOf(".xls") > 0 || file.name.indexOf(".xlsx") > 0 || file.name.indexOf(".xlsm") > 0) {
    fd = new FormData();
    fd.append("file", file.raw);
    fileData.value = file;
  } else {
    upload.value.clearFiles();
    ElMessage({
      message: "uploadTip",
      type: "error"
    });
  }
}
function removeFun() {
  upload.value.clearFiles();
}
const handleExceed = (files) => {
  upload.value.clearFiles();
  const file = files[0];
  upload.value.handleStart(file);
};

let formData = ref([]);
let formName = ref([]);
const submitUpload = async () => {
  const A = await readExcel(fileData.value);
  formData.value = A.ws;
  formName.value = A.wxName;
  console.log(formData.value);
  console.log(formName.value);
  for (let i of formData.value) {
    const maxLen = getMaxLenInArr(i);
    for (let j in i) {
      let completion = true;
      for (let k in i[j]) {
        if (i[j][k].length > 30) {
          completion = false;
        }
      }
      if (completion) {
        for (let s = i[j].length; s < maxLen; s++) {
          i[j].push("");
        }
      }
    }
  }
};

const addNewRow = (index) => {
  const maxLen = getMaxLenInArr(formData.value[index]);
  const len = formData.value[index].length;
  formData.value[index][len] = [];
  for (let i = 0; i < maxLen; i++) {
    formData.value[index][len].push("");
  }
};

const addNewCol = (index) => {
  let canAdd = true;
  for (let i in formData.value[index]) {
    for (let j in formData.value[index][i]) {
      if (formData.value[index][i][j].length > 30) {
        canAdd = false;
      } else {
        canAdd = true;
      }
    }
    if (canAdd) {
      formData.value[index][i].push("")
    }
  }
}//https://blog.csdn.net/langwang_100/article/details/134597236?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Ebaidujs_baidulandingword%7ECtr-3-134597236-blog-144502497.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Ebaidujs_baidulandingword%7ECtr-3-134597236-blog-144502497.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=6
</script>
<style lang="">

</style>